package com.chinatelecom.telecollege.sellerrewarding.service;

import com.chinatelecom.telecollege.sellerrewarding.Entity.product;
import com.chinatelecom.telecollege.sellerrewarding.repository.productRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by lenovo on 2017/6/21.
 */
@Service
public class productService {
    @Autowired
    private productRepo productRepo;

    @Transactional
    public product find(int id) {
        return productRepo.findById(id);
    }
    public List<product> findAll() {
        return productRepo.findAll();
    }
    public void mod(int id, int reward) {
        product product = productRepo.findById(id);
        product.setReward(reward);
        productRepo.save(product);
    }
    public void save(String name, int reward) {
        product product = new product();
        product.setName(name);
        product.setReward(reward);
        productRepo.save(product);
    }
    public void delete(int id) {
        productRepo.delete(id);
    }
}
